<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8" import="java.util.List"%>
<html>
<head>
<%@ include file="/jsp/include/header.jsp"%>
<script type="text/javascript" charset="UTF-8">
	var dg1;
	var d1;
	var f1;
	$(function() {

		f1 = $('#f1').form();
 
		d1 = $('#d1').show().dialog({
			modal : true,
			title : '报表参数',
			buttons : [ {
				text : '确定',
				handler : function() {	  
					var formData=f1.form("serialize");
					//formData.id=id;
					var data=JSON.stringify(formData);
					$("input[name=data]").val(data);
					 
					f1.form('submit', {
						url : '<%=ctx%>/report/rParam/save.htm',
						success : function(v) {
							try {
								 
								d1.dialog('close');
								$.messager.show({
									msg : '创建成功！',
									title : '提示'
								});
								dg1.datagrid('reload');
								 
							} catch (e) {
								$.messager.show({
									msg : '操作失败！',
									title : '提示'
								});
							}
						}
					});
					 
				}
			},{
				text : '取消',
				handler : function() {
					d1.dialog('close');
				}
			}]
		}).dialog('close');

		dg1 = $('#dg1').datagrid({
			url : '<%=ctx%>/report/rParam/list.htm',
			toolbar : '#toolbar',
			title : '报表参数',
			iconCls : 'icon-save',
			pagination : true,
			pageSize : 10,
			pageList : [ 10, 20],
			fit : true,
			fitColumns : true,
			nowrap : false,
			border : false,
			idField : 'p_id',
			frozenColumns : [ [ {
				field : 'p_id',
				width : 50,
				checkbox : true
			}] ],
			columns : [ [ 
			{
				field : 'title',
				title : '',
				width : 100
			},
			{
				field : 'name',
				title : '',
				width : 100
			},
			{
				field : 'type',
				title : 'select or input',
				width : 100
			},
			{
				field : 'class',
				title : '',
				width : 100
			},
			{
				field : 'data_options',
				title : '',
				width : 100
			},
			{
				field : 'width',
				title : '',
				width : 100
			}
			] ],
			onDblClickCell: function(index,field,value){
				var rows = dg1.datagrid('getRows');
				d1.dialog('open');
				f1.form('clear');
				f1.form('load','<%=ctx%>/report/rParam/get.htm?id='+rows[index].p_id);
				
			}
		});

	});

	function append() {
		d1.dialog('open');
		f1.form('clear');
	}

	function edit() {
		var rows = dg1.datagrid('getSelections');
		if (rows.length != 1 && rows.length != 0) {
			$.messager.show({
				msg : '只能择一个记录编辑！您已经选择了【' + rows.length + '条',
				title : '提示'
			});
		} else if (rows.length == 1) {
			d1.dialog('open');
			f1.form('clear');
			f1.form('load','<%=ctx%>/report/rParam/get.htm?id='+rows[0].p_id);
		}else{
			$.messager.show({
				msg : '请选择一条记录进行操作',
				title : '提示'
			});
		}
	}
	
	function remove() {
		var ids = [];
		var rows = dg1.datagrid('getSelections');
		if (rows.length > 0) {
			$.messager.confirm('请确认', '您要删除当前所选项目？', function(r) {
				if (r) {
					for ( var i = 0; i < rows.length; i++) {
						ids.push(rows[i].p_id);
					}
					$.ajax({
						url : '<%=ctx%>/report/rParam/del.htm',
						data : {
							id : ids.join(',')
						},
						cache : false,
						success : function(response) {
							dg1.datagrid('unselectAll');
							dg1.datagrid('reload');
							$.messager.show({
								title : '提示',
								msg : '删除成功！'
							});
						}
					});
				}
			});
		} else {
			$.messager.alert('提示', '请选择要删除的记录！', 'error');
		}
	}

	function searchFun() {
		dg1.datagrid('load', {
			key : $('#toolbar input[name=key]').val() 
		});
	}
	function clearFun() {
		$('#toolbar input').val('');
		dg1.datagrid('load', {});
	}
</script>
</head>
<body class="easyui-layout">

<div region="center" border="false" style="overflow: hidden;">
		<div id="toolbar" class="datagrid-toolbar" style="height: auto;">
			<fieldset>
				<legend>筛选</legend>
				<table class="tableForm">
					 
					<tr> <th>关键字</th>
						<td><input name="key" style="width: 150px;" />
							<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchFun();" href="javascript:void(0);">查找</a>
							<a class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="clearFun();" href="javascript:void(0);">清空</a>
						</td>
					</tr>
				 
				</table>
			</fieldset>
			<div>
				<a class="easyui-linkbutton" iconCls="icon-add" onclick="append();" plain="true" href="javascript:void(0);">增加</a>
				<a class="easyui-linkbutton" iconCls="icon-remove" onclick="remove();" plain="true" href="javascript:void(0);">删除</a> 
				<a class="easyui-linkbutton" iconCls="icon-edit" onclick="edit();" plain="true" href="javascript:void(0);">编辑</a>
				<a class="easyui-linkbutton" iconCls="icon-undo" onclick="dg1.datagrid('unselectAll');" plain="true" href="javascript:void(0);">取消选中</a>
			</div>
		</div>
		<table id="dg1"></table>
	</div>
    <div id="d1" style="display: none;overflow: hidden;">
		<form id="f1" method="post">
		 <input name="p_id" type="hidden" />
		 <input name="data" type="hidden" />
		 <table class="tableForm">
		     <tr>
	 
			   <td style="width:70px;" >：</td>
			    <td style="width:150px;">    
				<input name="p_id" class="easyui-validatebox" required="true"/>
			    </td>
	 
			   <td style="width:70px;" >：</td>
			    <td style="width:150px;">    
				<input name="title" class="easyui-validatebox" required="true"/>
			    </td>
		     </tr>
		     <tr>
	 
			   <td style="width:70px;" >：</td>
			    <td style="width:150px;">    
				<input name="name" class="easyui-validatebox" required="true"/>
			    </td>
	 
			   <td style="width:70px;" >select or input：</td>
			    <td style="width:150px;">    
				<input name="type" class="easyui-validatebox" required="true"/>
			    </td>
		     </tr>
		     <tr>
	 
			   <td style="width:70px;" >：</td>
			    <td style="width:150px;">    
				<input name="class" class="easyui-validatebox" required="true"/>
			    </td>
	 
			   <td style="width:70px;" >：</td>
			    <td style="width:150px;">    
				<input name="data_options" class="easyui-validatebox" required="true"/>
			    </td>
		     </tr>
		     <tr>
	 
			   <td style="width:70px;" >：</td>
			    <td style="width:150px;">    
				<input name="width" class="easyui-validatebox" required="true"/>
			    </td>
			   <td style="width:70px;" ></td>
			    <td style="width:150px;">    
				
			    </td>
			 
      </table>
  </form>
 </div>  
</body>
</html>